package com.imti.receiverdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.util.Log;

public class DynamicReceiver extends BroadcastReceiver
{

    private static final String TAG = DynamicReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent)
    {
        BatteryManager bm = context.getSystemService(BatteryManager.class);

        String action = intent.getAction();
        switch (action)
        {
            case Intent.ACTION_BATTERY_CHANGED:

                int batteryNow =
                    bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
                Log.d(TAG, "电池电量：" + batteryNow);
                break;

            case "com.imti.broadcast.NORMAL":
                Log.d(TAG, "接收到自定义广播");
                String text = intent.getStringExtra("extra_text");
                Log.d(TAG, "局部广播接收器接收到：" + text);
                break;
        }
    }
}
